<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'goods.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   <script src="js/jquery-1.11.3.min.js"></script>
	<script type="text/javascript">


	$(document).ready(function queryGoods() {
		$.ajax({
			url:"queryGoods.do",
			dataType:"json",
            type: 'get',  
            success: function (data) {
            	var table = $("#table");
                table.empty();
                table.append("<thead><tr height='30px'><th>序号</th><th>商品名称</th><th>商品描述</th><th>图片</th><th>操作</th></tr></thead><tbody>");
	           	for (var i=0;i<data.length;i++) {
	           		 var object = data[i];
	           		 table.append('<tr><td>'+(i+1)+'</td>+<td>'+object.goodName+'</td>+<td>'+object.goodDiscr+'</td>+<td>'+object.goodUrl+'</td><td>修改</td> 查看结果</td></tr>');
	           	 }
	           	 table.append("</tbody>");
            }
		});
	});

	function SaveGoods() {
		var goodName = $('#goodName').val();
		var goodDiscr = $('#goodDiscr').val();
		console.log(goodName,goodDiscr);
		$.ajax({
			url : "SaveGoods.do",
			data : {
				goodName :  $('#goodName').val(),
				goodDiscr : $('#goodDiscr').val(),
			},
			dataType : "json",
			type : 'POST',
			success : function(data) {
				
			}
		});
	}
	</script>
  
   	<div>
		<table id="table">
			<thead>
				<tr>
					<td>商品名称</td>
					<td>商品描述</td>
					<td>图片</td>
					<td>操作</td>
				</tr>
			</thead>
			<tbody>

			</tbody>
		</table>
	</div>
	<div>
		<span>商品名称</span>
		<input type="text" id="goodName" name="goodName">
	</div>
	<div>
		<span>商品描述</span>
		<input type="text" id="goodDiscr" name="goodDiscr">
	</div>
	<div>
		<span>商品图片</span>
		<img alt="" src="">
	</div>
	<div>
		<input type="button" value="上传图片">
		<input type="button" value="保存" onclick="SaveGoods()">
	</div>
  </body>
</html>
